<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/header.jsp"%>
<%@taglib prefix="code" tagdir="/WEB-INF/tags"%>
<html>
	<body class="easyui-layout list_body">
		<div class="list_body_north" data-options="region:'north'" border="false">
		 	<!-- 查询表单 -->
		 	<div  class="datagrid-toolbar" border="false"  >
					<span>登录账号:</span>
					<input type="text" id="login_name"  class="easyui-textbox" />
					<span style="margin-left:10px">真实姓名:</span>
					<input type="text" id="user_name"  class="easyui-textbox" />
					<span style="margin-left:10px">用户类型:</span>
					<code:codeSelect name="user_category" id="user_category" code_type="USER_CATEGORY" showSelect="true"></code:codeSelect>
					<span style="margin-left:10px">所属角色:</span>
					<input type="text" id="roleName"  class="easyui-textbox" />
					<span style="margin-left:10px">机构号:</span>
					<input type="text" id="ins_cd"  class="easyui-textbox" />
					<span style="margin-left:10px">机构名称:</span>
					<input type="text" id="ins_cn_nm"  class="easyui-textbox" />
					<span style="margin-left:10px">用户状态:</span>
					<code:codeSelect name="user_st" id="user_st" code_type="USER_STATUS" showSelect="true"></code:codeSelect>
				 	<a href="#" class="easyui-linkbutton btn" iconCls="icon-search" onclick="doSearch()" iconCls="icon-search">查询</a>
				 	<a href="#" class="easyui-linkbutton btn" iconCls="icon-reload" onclick="resetForm()" iconCls="icon-reload">重置</a>
			</div>
			<!-- 自定义标签工具栏 -->
			<jiepos:buttonOperateTag menuCode="${menuCode}"></jiepos:buttonOperateTag>
		</div>
		<div data-options="region:'center'" border="false" class="list_body_center">
			<!-- 表格 -->
		    <table id="userTable" fit="true"></table>
	    </div>
	    <div id="roleTree">
	    	<table id="userRoleTable"></table>
	    </div>
	</body>
	<script type="text/javascript">
		var grid;
		$(function(){
			/*加载表格数据*/
			grid = $("#userTable").jpgrid({
				url: "getUserInfListJson.do",
				columns: [
					{title: "登陆账号", field: "LOGIN_NAME", width: 80},
					{title: "真实姓名", field: "USER_NAME", width: 100},
					{title: "用户类别", field: "USER_CATEGORY", width: 80},
					{title: "所属角色", field: "ROLE_NAME", width: 100},
					{title: "所属机构", field: "INS_CN_NM", width: 220},
					{title: "用户状态", field: "USER_ST", width: 70}
				]
			});
		});
		
		/*查询方法*/
		function doSearch(){ 
			grid.load({
				login_name: $('#login_name').val(),
				user_name: $('#user_name').val(),
				user_category: $('#user_category').val(),
				roleName: $('#roleName').val(),
				user_st: $('#user_st').val(),
				ins_cd: $('#ins_cd').val(),
				ins_cn_nm: $('#ins_cn_nm').val()
			});
		}
		
		/*新增方法*/
		function addUser(url){
			commonDetail(url, "save");
		}
		
		/*修改方法*/
		function modifyUser(url){
			commonDetail(url, "update", "userTable");
		}
		
		/*删除方法*/
		function deleteUser(url){
			commonDel(url, "delete", "userTable");
		}
		
		/*启用方法*/
		function enabledUser(url){
			asyncOper(url, "确定启用选择的用户吗");
		}
		
		/*停用方法*/
		function lockedUser(url){
			asyncOper(url, "确定停用选择的用户吗");
		}
		
		/*重置密码*/
		function resetPwd(url){
			asyncOper(url, "确定重置选择的用户登陆密码吗");
		}
		
		/*权限设置*/
		var user_uuid;
		function roleSet(url){
			var checkedItems = checkSelected("userTable", true);
			if(!checkedItems){
				return;
			}
			user_uuid = checkedItems[0].UUID;
			/*加载角色数据*/
			var roleGrid = $("#userRoleTable").jpgrid({
				url: url,
				singleSelect: true,// 只能选择一条记录
				pageSize: 100,
				columns: [
					{title: "角色名称", field: "ROLE_NAME", width: "90px"},
					{title: "角色类型", field: "ROLE_TP_DESC", width: "70px"},
					{title: "所属机构", field: "INS_CN_NM", width: "185px"},
					{title: "角色描述", field: "ROLE_DESC", width: "100px"}
				],
				onLoadSuccess: function(data){
					$.each(data.rows, function(i, rowData){
						if(rowData.UUID === checkedItems[0].ROLE_UUID){
							roleGrid.selectRow(i);
							return false;
						}
					});
				}
			});
			openModal("#roleTree", {width:900, height:500, title: "角色选择"}, save);
		}
		
		/*保存*/
		function save(){
			var checkedItems = checkSelected("userRoleTable", true);
			if(!checkedItems){
				return;
			}
			$.jpajax({
				url: "saveUserRole.do",
				data: {user_uuid: user_uuid, role_uuid: checkedItems[0].UUID},
				success: function(result){
					if(result === true){
						grid.load();
						$.jpmessage.info("用户角色设置成功！");
					}else{
						$.jpmessage.error("用户角色设置失败！");
					}
				}
			});
		}
		
		function asyncOper(url, msg){
			commonAsync(url, "userTable", msg, function(result){
				grid.reload();
			});
		}
	</script>
</html>
